# !/usr/bin/env python
# -*- coding:utf-8 -*-
# @FileName : zsj.py
# @Time     : 2024/4/21 22:16
# @Author   : Robot-Zsj
"""
description:

i:
3
a b c

o:

abc
acb
bac
bca
cab
cba
"""
n = int(input())
arr = input().split()

path = []
used = [False] * n
cache = set()


def dfs():
    if len(path) == n:
        cache.add("".join(path))
        return

    for i in range(n):
        if used[i]:
            continue

        if i > 0 and arr[i] == arr[i - 1] and not used[i - 1]:
            continue

        path.append(arr[i])
        used[i] = True
        dfs()
        used[i] = False
        path.pop()


def getResult():
    arr.sort()
    dfs()

    for v in sorted(list(cache)):
        print(v)


getResult()
